package com.tian.view.custom

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import com.tian.view.BaseRecyclerAdapter
import com.tian.view.databinding.ActivityNestedScrollRecyclerViewBinding

/**
 * @author tiansongtao, Email:tiansongtao@up366.com
 * @date 2022/12/12 15:14
 */
class HeadRecyclerViewActivity : AppCompatActivity() {

    private lateinit var b: ActivityNestedScrollRecyclerViewBinding

    private val data: MutableList<BaseRecyclerAdapter.DataHolder> by lazy {
        val temp = mutableListOf<BaseRecyclerAdapter.DataHolder>()
        for (it in 0..20) {
            temp.add(BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "songtao $it"))
        }
        temp
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        b = ActivityNestedScrollRecyclerViewBinding.inflate(layoutInflater)
        setContentView(b.root)
        supportActionBar?.title = this::class.java.simpleName
        b.rv.layoutManager = LinearLayoutManager(this)
        val adapter = BaseRecyclerAdapter()
        b.rv.adapter = adapter
        adapter.datas = data
        b.swipeRefresh.setOnRefreshListener {
            data.add(1, BaseRecyclerAdapter.DataHolder(BaseRecyclerAdapter.TYPE_COMMON_BUTTON, "nihao 0"))
            adapter.notifyItemInserted(1)
            b.swipeRefresh.postDelayed({ b.swipeRefresh.isRefreshing = false }, 1000)
        }

    }

}